﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ExamSharedClasses {
    /// <summary>
    /// (k) ExamUser ist die Spezialisierung von ExamQuestions, das eine Klausurvorlage darstellt.
    /// Mit dem "ExamUser-Aufsatz" entsteht eine "Instanz einer Klausur" mit Schreibenden. Die Zeit
    /// des Schreibens wird mit Anfangs- und Endzeitpunkt festgelegt.
    /// </summary>
    [Serializable()]
    public class ExamUser : ExamWithQuestions {
        public new const string TABLENAME = "exam_user";
        public const string START_DATETIME = "start_datetime";
        public const string USER_ID = "user_id";
        public const string END_DATETIME = "end_datetime";

        public UserDetails UserDetails { get; set; }
        public DateTime StartDateTime { get; set; }
        public DateTime EndDateTime { get; set; }

        public ExamUser( UserDetails userDetails ) {
            this.UserDetails = userDetails;
            this.StartDateTime = new DateTime();
            this.EndDateTime = new DateTime();
        }
        public ExamUser( ExamWithQuestions examQuestions ) : base (examQuestions) {
            this.UserDetails = new UserDetails();
            this.StartDateTime = new DateTime();
            this.EndDateTime = new DateTime();
        }
        public ExamUser( UserDetails userDetails, ExamWithQuestions examQuestions )
            : base(examQuestions) {
            this.UserDetails = userDetails;
            this.StartDateTime = new DateTime();
            this.EndDateTime = new DateTime();
        }
        public ExamUser( UserDetails examUser, DateTime startDateTime, DateTime endDateTime, DateTime ratingDateTime, ExamWithQuestions examQuestions )
            : base( examQuestions ) {
            this.UserDetails = examUser;
            this.StartDateTime = startDateTime;
            this.EndDateTime = endDateTime;
        }
        public ExamUser( UserDetails user, DateTime startDateTime, DateTime endDateTime, DateTime ratingDateTime,   // ExamUser
                         List<Answer> answerList, List<int> pointsList,                // ExamQuestions
                         int examId, Class examClass, Module examModule, string examName, DateTime examCreateDate, DateTime examWriteDate, int examDuration, User examAuthor )  // Exam
            : base (new ExamWithQuestions(answerList, pointsList, new Exam(examId, examClass, examModule, examName, examCreateDate, examWriteDate, examDuration, examAuthor))) {
            this.UserDetails = user;
            this.StartDateTime = startDateTime;
            this.EndDateTime = endDateTime;
        }
        public override string ToString() {
            StringBuilder sb = new StringBuilder( "abgelegte Klausur:\n" );
            //if ( Exam != null )
            //    sb.Append( '\t' + Exam.ToString() );
            //if ( UserDetails != null )
            //    sb.Append( '\t' + UserDetails.ToString() );
            if ( StartDateTime != null )
                sb.Append( StartDateTime.ToString() + ", " );
            if ( EndDateTime != null )
                sb.Append( EndDateTime.ToString() + ", " );
            if ( GetAchievedPoints()>=0 )
                sb.Append( "erreichte Punkte: " + GetAchievedPoints() + '\n');
            return sb.ToString() + base.ToString();
        }
    }
}